import axios from '@/services/http.js';
import {
    ProList,
    UserLogin,
    SecKill,
    ProDetail,
    CartAdd,
    CartList,
    CartNum,
    CheckOne,
    CheckAll,
    RecommendList,
    AddressAdd,
    AddressList,
    CheckPhone,
    SendCode,
    CheckCode,
    UserRegist,
    AddressEdit,
    CartRemove,
    AddressDelete,
    HotSearch,
    Search,
} from '../config/url';

/* ----- 登录注册 ----- */
// 验证手机号码是否被注册过
export const checkPhone = (data) => {
    return axios.post(CheckPhone, data)
}
// 发送短信验证码
export const sendCode = (tel) => {
    return axios.post(SendCode, { tel })
}
// 验证短信验证码
export const checkCode = (data) => {
    return axios.post(CheckCode, data);
}
// 注册
export const register = (data) => {
    return axios.post(UserRegist, data);
}
//登录请求
export const login = (data) => {  //data里传过来的有loginname 和password
    return axios({
        url: UserLogin,
        method: 'post',
        data
    })
}
/* ----- 首页 ----- */
//获取产品的分页列表
export const getProductList = (count = 1) => {  //count 是分页的页码
    console.log("getPRodcutList")
    //return request.get("/pro/list",{params:{count}})
    // return request.get("/pro/list?count="+count)
    return axios({
        url: ProList,
        method: 'get',
        params: { count }
    })
}
// 秒杀
export const seckillList = () => {
    return axios.get(SecKill)
}
// 商品详情
export const proDetail = (id) => {
    return axios.get(ProDetail + id)
}
// 热门搜索
export const hotSearch = () => {
    return axios(HotSearch)
}
// 关键字搜索
export const keySearch = (keyword, count = 1) => {
    return axios({
        url: Search,
        params: {
            count,
            keyword
        }
    })
}
/* ----- 购物车 ----- */
// 加入购物车
export const cartAdd = (data) => {
    return axios({
        url: CartAdd,
        method: 'POST',
        data
    })
}
// 查看购物车
export const cartList = (id) => {
    return axios({
        url: CartList,
        method: 'POST',
        data: {
            userid: id
        }
    })
}
// 更新购物车数量
export const cartNum = (data) => {
    return axios({
        url: CartNum,
        method: 'post',
        data
    })
}
// 更新当前购物车数据的选中状态
export const checkOne = (data) => {
    return axios({
        url: CheckOne,
        method: 'post',
        data
    })
}
// 更新所有购物车数据的选中状态
export const checkAll = (data) => {
    return axios({
        url: CheckAll,
        method: 'post',
        data
    })
}
// 删除购物车单条数据
export const removeCart = (id) => {
    return axios({
        url: CartRemove,
        method: 'post',
        data: { cartid: id }
    })
}
// 获取推荐产品列表的数据
export const recommendList = () => {
    return axios(RecommendList)
}
/* ------地址------- */
// 添加地址
export const addressAdd = (data) => {
    return axios({
        url: AddressAdd,
        method: 'POST',
        data
    })
}
// 地址列表
export const addressList = (id) => {
    return axios({
        url: AddressList,
        params: {
            userid: id
        }
    })
}
// 修改地址
export const addressEdit = (data) => {
    return axios({
        url: AddressEdit,
        method: 'POST',
        data
    })
}
// 删除地址
export const addressDelete = (id) => {
    return axios({
        url: AddressDelete,
        method: 'post',
        data: {
            addressid: id
        }
    })
}